/*
 * mfc codec encoding example application
 * Andrzej Hajda <a.hajda@samsung.com>
 *
 * Main file of the application.
 *
 * Copyright 2012 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <stdio.h>
#include <string.h>
#include <pthread.h>

#include "common.h"
#include "args.h"
#include "in_demo.h"
#include "in_camera.h"
#include "in_uvc.h"
#include "out_file.h"
#include "io_dev.h"
#include "mfc.h"
#include "fimc.h"
#include "v4l_dev.h"
#include "h264_encode.h"

int main(int argc, char *argv[])
{
	void *buf;
	int size;
	int i;

	struct options opts;

	memset(&opts, 0, sizeof(struct options));
	opts.mfc_name = "/dev/video9";
	opts.in_name = "/dev/video0";
	opts.out_name = "out.mp4";
	opts.fimc_name = "/dev/video10";
	opts.codec = V4L2_PIX_FMT_H264;
	opts.duration = 300;
	opts.rate = 10;
	opts.height = 720;
	opts.width = 1280;
	opts.in_height = 720;
	opts.in_width = 1280;

	if(camera_init(opts) < 0){
		err("camera init err");
		return -1;
	}

	if(h264_init(opts) < 0){
		err("h264 init err");
		return -1;
	}
	size = opts.height * opts.width *2;
	buf = malloc(size);
	for(i = 0; i < opts.duration; i++){
		size = get_image_buf((void *)&buf);
		post_h264_buf(buf, size);
		post_image_buf();
	}
	wait_h264_finish();
	h264_exit();
	camera_exit();
}
